class Solution {
public:
    int countBinarySubstrings(string s) {
        int pre_count = 0, cur_count = 1, result = 0;
        s.append(1, '2');
        // cout<<s;
        for(int i = 0; i < s.length() - 1; i++)
        {
            if(s[i] != s[i + 1])
            {
                result += min(pre_count, cur_count);
                pre_count = cur_count;
                cur_count = 1;
            }
            else
            {
                cur_count++;
            }
        }
        return result;
    }
};
